package org.hackystat.sdsa.analyzer.model;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.logging.Logger;

import javax.xml.datatype.XMLGregorianCalendar;

import org.hackystat.sdsa.analyzer.model.activity.BufferTransActivity;
import org.hackystat.sdsa.analyzer.model.activity.TestBufferTransActivity;
import org.hackystat.sdsa.service.resource.devstream.jaxb.MacroBehavior;
import org.hackystat.sdsa.service.resource.devstream.jaxb.MicroBehavior;
import org.hackystat.sensorbase.resource.sensordata.jaxb.SensorData;
import org.hackystat.utilities.tstamp.Tstamp;
import org.junit.Before;
import org.junit.Test;

/**
 * Test episode.
 * 
 * @author hongbing
 *
 */
public class TestEpisode {
  /** Episode */
  private Episode episode;
  /** A buffer trans activities. */
  private BufferTransActivity bufferTrans;
  
  /**
   * Prepares test variables.
   * 
   * @throws Exception If error occurs.
   */
  @Before public void setUp() throws Exception {
    this.episode = new Episode();

    SensorData sensorData = new SensorData();
    XMLGregorianCalendar tstamp = Tstamp.makeTimestamp("2005-12-01T08:30:00");
    sensorData.setTimestamp(tstamp);
    sensorData.setResource("file:/C:/cvs/work/com/foo/Bar.java");
    sensorData.setSensorDataType("DevEvent");
    
    Logger logger = Logger.getLogger(TestBufferTransActivity.class.getName());
    this.bufferTrans = new BufferTransActivity(sensorData, logger);
  }
  

  
  /**
   * Test empty episode.
   * 
   */
  @Test public void testEmptyEpisode() {
    assertTrue("Activity list is empty by default", this.episode.getActivityList().isEmpty());
  }
  
  /**
   * Test the iterator of activities.
   */
  @Test public void testEpisode() {
    this.episode.addActivity(bufferTrans);
    assertTrue("A buffer trans activity exists", this.episode.getActivityList().size() > 0);
    
    MicroBehavior microBehavior = new MicroBehavior();
    microBehavior.setBehavior("refactoring");
    microBehavior.setExplanation("Method rename.");
    
    MacroBehavior macroBehavior = new MacroBehavior();
    macroBehavior.setBehavior("TDD");
    macroBehavior.setExplanation("Refactoring after test-first");
    
    assertNull("Test MicroBehavior nullness", this.episode.getMicroBehavior());
    this.episode.setMicroBehavior(microBehavior);
    assertNotNull("Test MicroBehavior nullness after set", this.episode.getMicroBehavior());

    assertNull("Test MacroBehavior nullness", this.episode.getMacroBehavior());
    this.episode.setMacroBehavior(macroBehavior);
    assertNotNull("Test MacroBehavior nullness after set", this.episode.getMacroBehavior());
  }
}
